/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} k
 * @return {ListNode}
 */
 var swapNodes = function(head, k) {
    let node = JSON.parse(JSON.stringify(head[k-1]))
    console.log(node)
    head[k-1] = JSON.parse(JSON.stringify(head[head.length- k-1]))
    console.log(head[k-1])
    head[head.length - k - 1] = node
    return head
};
console.log(swapNodes([1,2,3,4,5],2))
function ListNode(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
}